/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GUISupplier.java
 *
 * Created on 31-03-2011, 09:58:12
 */

package GUILayer;

import ControlLayer.CtrPostalCity;
import ControlLayer.CtrSupplier;
import ModelLayer.PostalCity;
import ModelLayer.Supplier;
import java.util.ArrayList;

/**
 *
 * @author Henrik
 */
public class GUISupplier extends javax.swing.JFrame {

    /** Creates new form GUISupplier */
    public GUISupplier() {
        initComponents();
        setVisible(true);
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel7 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        searchPanel = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        searchIdField = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        searchNameField = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        searchStreetField = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        searchStreetNoField = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        searchCityField = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        searchZipCodeField = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        searchCountryField = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        searchPhoneField = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        searchEmailField = new javax.swing.JTextField();
        searchButton = new javax.swing.JButton();
        clearButton1 = new javax.swing.JButton();
        searchStatusLabel = new javax.swing.JLabel();
        insertPanel = new javax.swing.JPanel();
        jLabel21 = new javax.swing.JLabel();
        insertNameField = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        insertStreetField = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        insertStreetNoField = new javax.swing.JTextField();
        jLabel24 = new javax.swing.JLabel();
        insertCityField = new javax.swing.JTextField();
        jLabel25 = new javax.swing.JLabel();
        insertZipCodeField = new javax.swing.JTextField();
        jLabel26 = new javax.swing.JLabel();
        insertCountryField = new javax.swing.JTextField();
        jLabel27 = new javax.swing.JLabel();
        insertPhoneField = new javax.swing.JTextField();
        jLabel28 = new javax.swing.JLabel();
        insertEmailField = new javax.swing.JTextField();
        insertButton = new javax.swing.JButton();
        clearButton2 = new javax.swing.JButton();
        insertStatusLabel = new javax.swing.JLabel();
        updatePanel = new javax.swing.JPanel();
        jLabel29 = new javax.swing.JLabel();
        updateIdField = new javax.swing.JTextField();
        jLabel30 = new javax.swing.JLabel();
        updateNameField = new javax.swing.JTextField();
        jLabel31 = new javax.swing.JLabel();
        updateStreetField = new javax.swing.JTextField();
        jLabel32 = new javax.swing.JLabel();
        updateStreetNoField = new javax.swing.JTextField();
        jLabel33 = new javax.swing.JLabel();
        updateCityField = new javax.swing.JTextField();
        jLabel34 = new javax.swing.JLabel();
        updateZipCodeField = new javax.swing.JTextField();
        jLabel35 = new javax.swing.JLabel();
        updateCountryField = new javax.swing.JTextField();
        jLabel36 = new javax.swing.JLabel();
        updatePhoneField = new javax.swing.JTextField();
        jLabel37 = new javax.swing.JLabel();
        updateEmailField = new javax.swing.JTextField();
        updateButton = new javax.swing.JButton();
        clearButton3 = new javax.swing.JButton();
        updateStatusLabel = new javax.swing.JLabel();
        deletePanel = new javax.swing.JPanel();
        jLabel38 = new javax.swing.JLabel();
        deleteIdField = new javax.swing.JTextField();
        jLabel39 = new javax.swing.JLabel();
        deleteNameField = new javax.swing.JTextField();
        deleteButton = new javax.swing.JButton();
        clearButton = new javax.swing.JButton();
        deleteStatusLabel = new javax.swing.JLabel();
        allSuppliersPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        loadButton = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        jLabel7.setText("jLabel7");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Microsoft Sans Serif", 0, 18));
        jLabel1.setText("Supplier menu");

        jLabel11.setText("Id");

        jLabel12.setText("Name");

        jLabel13.setText("Street");

        jLabel14.setText("Street #");

        jLabel15.setText("City");

        jLabel16.setText("Zip code");

        jLabel17.setText("Country");

        jLabel18.setText("Phone #");

        jLabel19.setText("Email");

        searchButton.setText("Search");
        searchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchButtonActionPerformed(evt);
            }
        });

        clearButton1.setText("Clear");
        clearButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout searchPanelLayout = new javax.swing.GroupLayout(searchPanel);
        searchPanel.setLayout(searchPanelLayout);
        searchPanelLayout.setHorizontalGroup(
            searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(searchPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(searchPanelLayout.createSequentialGroup()
                        .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel11)
                            .addComponent(jLabel12)
                            .addComponent(jLabel13)
                            .addComponent(jLabel15)
                            .addComponent(jLabel16)
                            .addComponent(jLabel17)
                            .addComponent(jLabel18)
                            .addComponent(jLabel14))
                        .addGap(28, 28, 28)
                        .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(searchPhoneField)
                            .addComponent(searchIdField, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(searchZipCodeField, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(searchCountryField)
                            .addComponent(searchCityField)
                            .addComponent(searchStreetField)
                            .addComponent(searchNameField, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
                            .addComponent(searchStreetNoField, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(searchEmailField, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)))
                    .addComponent(jLabel19)
                    .addGroup(searchPanelLayout.createSequentialGroup()
                        .addComponent(searchButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(clearButton1))
                    .addComponent(searchStatusLabel))
                .addContainerGap(328, Short.MAX_VALUE))
        );
        searchPanelLayout.setVerticalGroup(
            searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(searchPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(searchIdField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(searchNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(searchStreetField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(searchStreetNoField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(searchCityField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(searchZipCodeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(searchCountryField, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(searchPhoneField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel19)
                    .addComponent(searchEmailField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(searchButton)
                    .addComponent(clearButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(searchStatusLabel)
                .addContainerGap(126, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Search", searchPanel);

        jLabel21.setText("Name");

        jLabel22.setText("Street");

        jLabel23.setText("Street #");

        jLabel24.setText("City");

        jLabel25.setText("Zip code");

        jLabel26.setText("Country");

        jLabel27.setText("Phone #");

        jLabel28.setText("Email");

        insertButton.setText("Insert");
        insertButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                insertButtonActionPerformed(evt);
            }
        });

        clearButton2.setText("Clear");
        clearButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout insertPanelLayout = new javax.swing.GroupLayout(insertPanel);
        insertPanel.setLayout(insertPanelLayout);
        insertPanelLayout.setHorizontalGroup(
            insertPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(insertPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(insertPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(insertPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel21)
                        .addGroup(insertPanelLayout.createSequentialGroup()
                            .addGroup(insertPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel22)
                                .addComponent(jLabel23)
                                .addComponent(jLabel25)
                                .addComponent(jLabel24)
                                .addComponent(jLabel26)
                                .addComponent(jLabel27)
                                .addComponent(jLabel28))
                            .addGap(28, 28, 28)
                            .addGroup(insertPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(insertEmailField, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
                                .addGroup(insertPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(insertStreetNoField, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(insertZipCodeField, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(insertPhoneField)
                                    .addComponent(insertCountryField)
                                    .addComponent(insertCityField)
                                    .addComponent(insertStreetField)
                                    .addComponent(insertNameField, javax.swing.GroupLayout.PREFERRED_SIZE, 291, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(insertPanelLayout.createSequentialGroup()
                        .addGroup(insertPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(insertPanelLayout.createSequentialGroup()
                                .addComponent(insertButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(clearButton2))
                            .addComponent(insertStatusLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 236, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(328, 328, 328))
        );
        insertPanelLayout.setVerticalGroup(
            insertPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(insertPanelLayout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addGroup(insertPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel21)
                    .addComponent(insertNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(insertPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel22)
                    .addComponent(insertStreetField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(insertPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel23)
                    .addComponent(insertStreetNoField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(insertPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel24)
                    .addComponent(insertCityField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(insertPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel25)
                    .addComponent(insertZipCodeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(insertPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel26)
                    .addComponent(insertCountryField, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(insertPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel27)
                    .addComponent(insertPhoneField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(insertPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel28)
                    .addComponent(insertEmailField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(insertPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(insertButton)
                    .addComponent(clearButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(insertStatusLabel)
                .addContainerGap(125, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Insert", insertPanel);

        jLabel29.setText("Id");

        jLabel30.setText("Name");

        jLabel31.setText("Street");

        jLabel32.setText("Street #");

        jLabel33.setText("City");

        jLabel34.setText("Zip code");

        jLabel35.setText("Country");

        jLabel36.setText("Phone #");

        jLabel37.setText("Email");

        updateButton.setText("Update");
        updateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateButtonActionPerformed(evt);
            }
        });

        clearButton3.setText("Clear");
        clearButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout updatePanelLayout = new javax.swing.GroupLayout(updatePanel);
        updatePanel.setLayout(updatePanelLayout);
        updatePanelLayout.setHorizontalGroup(
            updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(updatePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(updatePanelLayout.createSequentialGroup()
                        .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel29)
                            .addComponent(jLabel30))
                        .addGap(42, 42, 42)
                        .addComponent(updateIdField, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(updatePanelLayout.createSequentialGroup()
                        .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel31)
                            .addComponent(jLabel32)
                            .addComponent(jLabel34)
                            .addComponent(jLabel33)
                            .addComponent(jLabel35)
                            .addComponent(jLabel36)
                            .addComponent(jLabel37))
                        .addGap(28, 28, 28)
                        .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(updateStreetNoField, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(updateZipCodeField, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(updatePhoneField)
                            .addComponent(updateCountryField)
                            .addComponent(updateCityField)
                            .addComponent(updateStreetField)
                            .addComponent(updateNameField, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
                            .addComponent(updateEmailField)))
                    .addGroup(updatePanelLayout.createSequentialGroup()
                        .addComponent(updateButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(clearButton3))
                    .addComponent(updateStatusLabel))
                .addContainerGap(328, Short.MAX_VALUE))
        );
        updatePanelLayout.setVerticalGroup(
            updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(updatePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel29)
                    .addComponent(updateIdField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel30)
                    .addComponent(updateNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel31)
                    .addComponent(updateStreetField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel32)
                    .addComponent(updateStreetNoField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel33)
                    .addComponent(updateCityField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel34)
                    .addComponent(updateZipCodeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel35)
                    .addComponent(updateCountryField, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel36)
                    .addComponent(updatePhoneField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel37)
                    .addComponent(updateEmailField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(updateButton)
                    .addComponent(clearButton3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(updateStatusLabel)
                .addContainerGap(125, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Update", updatePanel);

        jLabel38.setText("Id");

        jLabel39.setText("Name");

        deleteButton.setText("Delete");
        deleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteButtonActionPerformed(evt);
            }
        });

        clearButton.setText("Clear");
        clearButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout deletePanelLayout = new javax.swing.GroupLayout(deletePanel);
        deletePanel.setLayout(deletePanelLayout);
        deletePanelLayout.setHorizontalGroup(
            deletePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(deletePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(deletePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(deletePanelLayout.createSequentialGroup()
                        .addGroup(deletePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel38)
                            .addComponent(jLabel39))
                        .addGap(42, 42, 42)
                        .addGroup(deletePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(deleteNameField, javax.swing.GroupLayout.PREFERRED_SIZE, 291, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(deleteIdField, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(deletePanelLayout.createSequentialGroup()
                        .addComponent(deleteButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(clearButton))
                    .addComponent(deleteStatusLabel))
                .addContainerGap())
        );
        deletePanelLayout.setVerticalGroup(
            deletePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(deletePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(deletePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel38)
                    .addComponent(deleteIdField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(deletePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel39)
                    .addComponent(deleteNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(deletePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(deleteButton)
                    .addComponent(clearButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(deleteStatusLabel)
                .addContainerGap(308, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Delete", deletePanel);

        jList1.setFont(new java.awt.Font("Courier New", 0, 11));
        jScrollPane1.setViewportView(jList1);

        jLabel2.setText("Id");

        jLabel3.setText("Name");

        loadButton.setText("Load");
        loadButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loadButtonActionPerformed(evt);
            }
        });

        jLabel4.setText("Street");

        jLabel6.setText("Zipcode");

        jLabel8.setText("City");

        jLabel9.setText("Country");

        jLabel5.setText("Phone#");

        jLabel10.setText("Email");

        javax.swing.GroupLayout allSuppliersPanelLayout = new javax.swing.GroupLayout(allSuppliersPanel);
        allSuppliersPanel.setLayout(allSuppliersPanelLayout);
        allSuppliersPanelLayout.setHorizontalGroup(
            allSuppliersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(allSuppliersPanelLayout.createSequentialGroup()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel3)
                .addGap(112, 112, 112)
                .addComponent(jLabel4)
                .addGap(70, 70, 70)
                .addComponent(jLabel8)
                .addGap(64, 64, 64)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel9)
                .addGap(55, 55, 55)
                .addComponent(jLabel5)
                .addGap(35, 35, 35)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 57, Short.MAX_VALUE)
                .addComponent(loadButton)
                .addContainerGap())
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 698, Short.MAX_VALUE)
        );
        allSuppliersPanelLayout.setVerticalGroup(
            allSuppliersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(allSuppliersPanelLayout.createSequentialGroup()
                .addGroup(allSuppliersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(allSuppliersPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(allSuppliersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel6)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9)
                            .addComponent(jLabel5)
                            .addComponent(jLabel10)))
                    .addComponent(loadButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 381, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("All suppliers", allSuppliersPanel);

        jMenu1.setText("Navigation");

        jMenuItem1.setText("Main menu");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 703, Short.MAX_VALUE)
                        .addGap(14, 14, 14))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 440, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:
        mainMenu();
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
        // TODO add your handling code here:
        deleteSupplier();
    }//GEN-LAST:event_deleteButtonActionPerformed

    private void updateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateButtonActionPerformed
        // TODO add your handling code here:
        updateSupplier();
    }//GEN-LAST:event_updateButtonActionPerformed

    private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearButtonActionPerformed
        // TODO add your handling code here:
        clear();
    }//GEN-LAST:event_clearButtonActionPerformed

    private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchButtonActionPerformed
        // TODO add your handling code here:
        search();
    }//GEN-LAST:event_searchButtonActionPerformed

    private void insertButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_insertButtonActionPerformed
        // TODO add your handling code here:
        insert();
    }//GEN-LAST:event_insertButtonActionPerformed

    private void clearButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearButton1ActionPerformed
        // TODO add your handling code here:
        clear();
    }//GEN-LAST:event_clearButton1ActionPerformed

    private void clearButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearButton2ActionPerformed
        // TODO add your handling code here:
        clear();
    }//GEN-LAST:event_clearButton2ActionPerformed

    private void clearButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearButton3ActionPerformed
        // TODO add your handling code here:
        clear();
    }//GEN-LAST:event_clearButton3ActionPerformed

    private void loadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadButtonActionPerformed
        // TODO add your handling code here:
        updateList();
    }//GEN-LAST:event_loadButtonActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GUISupplier().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel allSuppliersPanel;
    private javax.swing.JButton clearButton;
    private javax.swing.JButton clearButton1;
    private javax.swing.JButton clearButton2;
    private javax.swing.JButton clearButton3;
    private javax.swing.JButton deleteButton;
    private javax.swing.JTextField deleteIdField;
    private javax.swing.JTextField deleteNameField;
    private javax.swing.JPanel deletePanel;
    private javax.swing.JLabel deleteStatusLabel;
    private javax.swing.JButton insertButton;
    private javax.swing.JTextField insertCityField;
    private javax.swing.JTextField insertCountryField;
    private javax.swing.JTextField insertEmailField;
    private javax.swing.JTextField insertNameField;
    private javax.swing.JPanel insertPanel;
    private javax.swing.JTextField insertPhoneField;
    private javax.swing.JLabel insertStatusLabel;
    private javax.swing.JTextField insertStreetField;
    private javax.swing.JTextField insertStreetNoField;
    private javax.swing.JTextField insertZipCodeField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel36;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel38;
    private javax.swing.JLabel jLabel39;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JList jList1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JButton loadButton;
    private javax.swing.JButton searchButton;
    private javax.swing.JTextField searchCityField;
    private javax.swing.JTextField searchCountryField;
    private javax.swing.JTextField searchEmailField;
    private javax.swing.JTextField searchIdField;
    private javax.swing.JTextField searchNameField;
    private javax.swing.JPanel searchPanel;
    private javax.swing.JTextField searchPhoneField;
    private javax.swing.JLabel searchStatusLabel;
    private javax.swing.JTextField searchStreetField;
    private javax.swing.JTextField searchStreetNoField;
    private javax.swing.JTextField searchZipCodeField;
    private javax.swing.JButton updateButton;
    private javax.swing.JTextField updateCityField;
    private javax.swing.JTextField updateCountryField;
    private javax.swing.JTextField updateEmailField;
    private javax.swing.JTextField updateIdField;
    private javax.swing.JTextField updateNameField;
    private javax.swing.JPanel updatePanel;
    private javax.swing.JTextField updatePhoneField;
    private javax.swing.JLabel updateStatusLabel;
    private javax.swing.JTextField updateStreetField;
    private javax.swing.JTextField updateStreetNoField;
    private javax.swing.JTextField updateZipCodeField;
    // End of variables declaration//GEN-END:variables

    private void mainMenu()
    {
        setVisible(false);
        GUIMainMenu gui = new GUIMainMenu();
    }

    private void postalMenu()
    {
        setVisible(false);
        GUIPostalCity gui = new GUIPostalCity();
    }

    private void deleteSupplier()
    {
        CtrSupplier ctrSup = new CtrSupplier();
        int id = Integer.parseInt(deleteIdField.getText());
        int result = ctrSup.deleteSupplier(id);
        if(result == 1)
        {
            clear();
            deleteStatusLabel.setText("Supplier with " + id + " is deleted");
        }
        else{
            deleteStatusLabel.setText("WRONG!");
        }
    }

    private void updateSupplier()
    {
        CtrSupplier ctrSupp = new CtrSupplier();
        int id = Integer.parseInt(updateIdField.getText());
        System.out.println("+" + id + "+");
        
        String name = updateNameField.getText();
        String street = updateStreetField.getText();
        int streetNo = Integer.parseInt(updateStreetNoField.getText());
        //PostalCity zipCode = ctrSupp.findSupplierById(id, false).getZipCode();
        String country = updateCountryField.getText();
        String phoneNo = updatePhoneField.getText();
        String email = updateEmailField.getText();

        int result = ctrSupp.updateSupplier(id, name, street, streetNo, country, phoneNo, email);
        if (result == 1){
            clear();
            updateStatusLabel.setText("Supplier is updated");
        }
        else{
            updateStatusLabel.setText("Problem with update");
        }
    }

    private void clear()
    {
        searchIdField.setText(null);
        searchNameField.setText(null);
        searchStreetField.setText(null);
        searchStreetNoField.setText(null);
        searchZipCodeField.setText(null);
        searchCityField.setText(null);
        searchCountryField.setText(null);
        searchPhoneField.setText(null);
        searchEmailField.setText(null);
        searchStatusLabel.setText(null);
        
        insertNameField.setText(null);
        insertStreetField.setText(null);
        insertStreetNoField.setText(null);
        insertZipCodeField.setText(null);
        insertCityField.setText(null);
        insertCountryField.setText(null);
        insertPhoneField.setText(null);
        insertEmailField.setText(null);
        insertStatusLabel.setText(null);

        updateIdField.setText(null);
        updateNameField.setText(null);
        updateStreetField.setText(null);
        updateStreetNoField.setText(null);
        updateZipCodeField.setText(null);
        updateCityField.setText(null);
        updateCountryField.setText(null);
        updatePhoneField.setText(null);
        updateEmailField.setText(null);
        updateStatusLabel.setText(null);

        deleteIdField.setText(null);
        deleteNameField.setText(null);
    }

    private void search()
    {
        CtrSupplier ctrSupp = new CtrSupplier();
        String input = searchIdField.getText();
        if(input.length() == 0)
        {
            input = searchNameField.getText();
            if(input.length() == 0){
                searchStatusLabel.setText("Insert id or name");
            }
            else{
                Supplier supplier = new Supplier();
                supplier = ctrSupp.findSupplierByName(input, true);
                putValuesOnTheScreen(supplier);
            }
        }
        else{
            Supplier supplier = new Supplier();
            supplier = ctrSupp.findSupplierById(Integer.parseInt(input), true);
            putValuesOnTheScreen(supplier);
        }
    }

    private void putValuesOnTheScreen(Supplier suppObj)
    {
        searchIdField.setText(String.valueOf(suppObj.getId()));
        searchNameField.setText(suppObj.getName());
        searchStreetField.setText(suppObj.getStreet());
        searchStreetNoField.setText(String.valueOf(suppObj.getStreetNo()));
        searchZipCodeField.setText(String.valueOf(suppObj.getZipCode().getPostalCode()));
        searchCityField.setText(suppObj.getZipCode().getCity());
        searchCountryField.setText(suppObj.getCountry());
        searchPhoneField.setText(suppObj.getPhoneNo());
        searchEmailField.setText(suppObj.getEmail());

        updateIdField.setText(String.valueOf(suppObj.getId()));
        updateNameField.setText(suppObj.getName());
        updateStreetField.setText(suppObj.getStreet());
        updateStreetNoField.setText(String.valueOf(suppObj.getStreetNo()));
        updateZipCodeField.setText(String.valueOf(suppObj.getZipCode().getPostalCode()));
        updateCityField.setText(suppObj.getZipCode().getCity());
        updateCountryField.setText(suppObj.getCountry());
        updatePhoneField.setText(suppObj.getPhoneNo());
        updateEmailField.setText(suppObj.getEmail());

        deleteIdField.setText(String.valueOf(suppObj.getId()));
        deleteNameField.setText(suppObj.getName());
        deleteStatusLabel.setText(null);
    }

    private void insert()
    {
        CtrSupplier ctrSupp = new CtrSupplier();
        CtrPostalCity ctrPost = new CtrPostalCity();
        Supplier supObj = new Supplier();
        String name = insertNameField.getText();
        String street = insertStreetField.getText();
        int streetNo = Integer.parseInt(insertStreetNoField.getText());
        PostalCity zipCode = ctrPost.findByZipCode(Integer.parseInt(insertZipCodeField.getText()));
        
        String country = insertCountryField.getText();
        String phone = insertPhoneField.getText();
        String email = insertEmailField.getText();
        supObj.setName(name);
        supObj.setStreet(street);
        supObj.setStreetNo(streetNo);
        supObj.setZipCode(zipCode);
        supObj.setCountry(country);
        supObj.setPhoneNo(phone);
        supObj.setEmail(email);
        int result = ctrSupp.insertSupplier(supObj);
        if (result == 1){
            clear();
            insertStatusLabel.setText(name + " is inserted with id: " + supObj.getId());
        }
        else{
            insertStatusLabel.setText("Something went wrong");
        }
    }

    private void updateList()
    {
        CtrSupplier ctrSupp = new CtrSupplier();
        ArrayList<Supplier> prod = ctrSupp.findAllSuppliers(true);
        buildList(prod);
    }

    private void buildList(ArrayList<Supplier> supplies)
    {
        String [] supply = new String[supplies.size()];
        int index = 0;
        for(Supplier sObj : supplies)
        {
            String sId = String.valueOf(sObj.getId());
            String name = sObj.getName();
            String street = sObj.getStreet() + " " + String.valueOf(sObj.getStreetNo());
            String zipCode = String.valueOf(sObj.getZipCode().getPostalCode());
            String city = sObj.getZipCode().getCity();
            String country = sObj.getCountry();
            String phoneNo = sObj.getPhoneNo();
            String email = sObj.getEmail();

            if(sId.length() < 2){
                int length = sId.length();
                while (length < 2)
                {
                    sId = sId + " ";
                    length++;
                }
            }
            if(name.length() > 20){
                name = name.substring(0, 19);
            }
            if(name.length() < 20){
                int length = name.length();
                while (length < 20)
                {
                    name = name + " ";
                    length++;
                }
            }
            if(street.length() > 15){
                street = street.substring(0,14);
            }
            if(street.length() <15){
                int length = street.length();
                while (length < 14)
                {
                    street = street + " ";
                    length++;
                }
            }
            if(city.length() > 12){
                city = city.substring(0, 11);
            }
            if(city.length() < 12){
                int length = city.length();
                while (length < 11)
                {
                    city = city + " ";
                    length++;
                }
            }
            if(country.length() > 12){
                country = country.substring(0, 11);
            }
            if(country.length() < 12){
                int length = country.length();
                while (length < 11)
                {
                    country = country + " ";
                    length++;
                }
            }
            
            supply[index] = (sId + " " + name + " " + street + " " + city + " " + zipCode + "   " + country + " " + phoneNo + "   " + email);
            index++;
        }
        jList1.setListData(supply);
    }
}
